package org.duiduo;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.engine.repository.Deployment;
import org.junit.Test;

/**
 * 部署流程到数据库中
 * 在非spring环境下
 */
public class FTest1 {

    private static final String url = "jdbc:mysql://49.235.153.173:3306/flowable-learn?serverTimezone=UTC&nullCatalogMeansCurrent=true";

    @Test
    public void test01() {
        // 流程引擎的配置对象 关联相关的数据源
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl(url)
                .setJdbcDriver("com.mysql.cj.jdbc.Driver")
                .setJdbcUsername("root")
                .setJdbcPassword("zaijian1220")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        // 获取流程引擎对象
        ProcessEngine processEngine = cfg.buildProcessEngine();
        System.out.println(processEngine);
        // 部署流程需要获取 RepositoryService对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                // 一次部署操作可以部署多个流程定义
                .addClasspathResource("process-01/FirstFlow.bpmn20.xml")
                .name("第一个流程图")
                .deploy();
        System.out.println("deploy id ====> " + deploy.getId());
    }
}
